##################################################################################
##############            FIGURE 1                  ##############################
##################################################################################

rm(list=ls())
setwd(" ")
load("data.Rdata")

#electoral
camp$colvar[camp$urban_dominate==1] <- "blue"
camp$colvar[camp$peasant_dominate==1] <- "red"
camp$colvar[camp$indwork_dominate==1] <- "green"

camp$pcvar[camp$urban_dominate==1] <- 10
camp$pcvar[camp$peasant_dominate==1] <- 8
camp$pcvar[camp$indwork_dominate==1] <- 2


pdf("figure1.pdf")
plot(as.numeric(camp$v2x_polyarchy_byear), as.numeric(camp$v2x_polyarchy_t1), xlab="Electoral democracy campaign start",
     ylab="Electoral democracy campaign end", col=camp$colvar, pch=camp$pcvar, cex=1.5, main="Electoral democracy changes")
legend("bottomright", c( "Peasants dominate", "Urban middle classes dominate",  "Industrial workers dominate"), 
       col=c("red", "blue", "green"), pch = c(8, 10, 2))
dev.off()

##################################################################################
##############            FIGURE A1                 ##############################
##################################################################################

peas <- aggregate(camp$peasant_dominate, by=list(camp$decdum_byear),FUN=mean, na.rm=T)
urb <- aggregate(camp$urban_dominate, by=list(camp$decdum_byear),FUN=mean, na.rm=T)
work <- aggregate(camp$indwork_dominate, by=list(camp$decdum_byear),FUN=mean, na.rm=T)

pdf("figure_A1.pdf")
plot(as.numeric(as.character(peas$Group.1)), as.numeric(peas$x), type="l", ylim=c(0,1), col="red", lwd=2, main="The social group profile of anti-regime campaigns over time")
lines(as.numeric(as.character(urb$Group.1)), as.numeric(urb$x), type="l", ylim=c(0,1), col="blue", lwd=2)
lines(as.numeric(as.character(work$Group.1)), as.numeric(work$x), type="l", ylim=c(0,1), col="green", lwd=2)
legend("topleft", c( "Peasants dominate", "Urban middle classes dominate",  "Industrial workers dominate"), col=c("red", "blue", "green"), lty = c(1, 1, 1), lwd=c(2,2,2))
dev.off()





